import 'package:enterprise_v6_app/app/core/constans/dict_data_info.dart';
import 'package:enterprise_v6_app/app/data/entities/application/filter/filter_bean.dart';
import 'package:enterprise_v6_app/app/data/entities/application/filter/filter_entities_bean.dart';
import 'package:enterprise_v6_app/app/data/entities/application/filter/filter_field_parameter_bean.dart';
import 'package:enterprise_v6_app/app/data/entities/application/get_dict_all_entity.dart';

/// 筛选通用方法
class FilterUtils {
  /// 获取字典筛选列表
  /// 根据对应关系,获取筛选列表
  // static Future<List<FilterBean>> getDictFilterList({required Map<String, String> screenMap}) async {
  static Future<List<FilterBean>> getDictFilterList({required List<FilterFieldParameterBean> fieldParameterList}) async {
    final List<FilterBean> allFilterList = [];
    for (var item in fieldParameterList) {
      // 字典值为空则不查询字典
      if (item.dictionaryType == null) {
        continue;
      }
      // 获取类别字典数组
      final List<GetDictAllEntity> dictList = await DictDataInfo.getDictionaryDataByTree(dictionaryType: item.dictionaryType!);
      // 筛选项数组
      final List<FilterEntitiesBean> filterList = [];
      for (var dict in dictList) {
        filterList.add(FilterEntitiesBean(name: dict.dictionaryLabel!, value: dict.id!));
      }
      // 筛选控制bean
      final FilterBean filterBean = FilterBean(title: item.screenName, filterList: filterList);
      // 添加筛选项
      allFilterList.add(filterBean);
    }
    return allFilterList;
  }
}
